//
//  jingwaixqTableViewController.m
//  PASystem
//
//  Created by michael on 16/8/22.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "jingwaixqTableViewController.h"

@interface jingwaixqTableViewController ()
@property(nonatomic,assign)int currentPage; //当前页
@property(nonatomic,strong)NSMutableArray * dataArray;
@property(nonatomic,strong)NSDictionary * dic;
@property(nonatomic,assign)int totalCounts; //总条数

@end

@implementation jingwaixqTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    UIColor *myColor = [UIColor colorWithWhite:0.8 alpha:0.3];
//    self.tableView.layer.borderWidth = 5;
//    self.tableView.layer.borderColor = [myColor CGColor];
     self.title = _string;
    self.view.backgroundColor = [UIColor whiteColor];
            [self loadData]; //加载网络数据
self.tableView.bounces = NO;
}
-(NSMutableArray*)dataArray{
    if (_dataArray == nil) {
      _dataArray =   [NSMutableArray array];
    }
    return _dataArray;
}
#pragma mark 加载网络数据
-(void)loadData{
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
 NSString *json =[NSString stringWithFormat: @"{'action':%@,'service': %@, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",_action,_service,userId,pwdId,userHumber,_id];
     NSArray * array = @[@{@"arg0":json}];
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {

       
     NSDictionary *dic = JSON[@"reason"];
        
    NSDictionary *dict = dic[@"attrs"];
//    NSLog(@"%@",dict);
    
    _dic = dict;
    [_dataArray addObject:dict];
    

//     NSLog(@"11%@",_dataArray);
        
        [self.tableView reloadData];
       
    } failure:^(NSError *error) {
        
    }];
 
}
- (void)viewDidAppear:(BOOL)animated
{
self.tableView.frame = CGRectMake(0, 64, KScreenWidth, KScreenHeight-46-64);
     UIColor *myColor = [UIColor colorWithWhite:0.8 alpha:0.3];
    
    self.tableView.layer.borderWidth = 10;
    self.tableView.layer.borderColor = [myColor CGColor];

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

if (indexPath.row==0) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"机构名称:";
  
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-120, label.height)];
 label2.numberOfLines = 0;
 label2.textAlignment = NSTextAlignmentRight;
    label2.text = _dic[@"JGNAME"];
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
if (indexPath.row==1) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"所属地区:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-120, label.height)];
  label2.textAlignment = NSTextAlignmentRight;

  
 
    label2.text = _dic[@"AREA"];
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }

if (indexPath.row==2) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"所属国家:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-120, label.height)];
 
   label2.textAlignment = NSTextAlignmentRight;

 
    label2.text = _dic[@"COUNTRY"];
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
if (indexPath.row==3) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"签约时间:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-120, label.height)];
   //时间
  NSString *string = _dic[@"SIGNTIME"];
  NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"MMM d, yyyy HH:mm:ss aa";
 fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
     NSDate *date = [fmt dateFromString:string];
     NSDateFormatter *fm = [[NSDateFormatter alloc] init];
    fm.dateFormat = @"yyyy-MM-dd";
     NSString *selfYear = [fm stringFromDate:date];

   label2.textAlignment = NSTextAlignmentRight;
    label2.text = selfYear;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
if (indexPath.row==4) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"签约地点:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-120, label.height)];
  label2.textAlignment = NSTextAlignmentRight;
    label2.text = _dic[@"LINKMAN"];
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
 
 if (indexPath.row==5) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"签约部门:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-120, label.height)];
  label2.textAlignment = NSTextAlignmentRight;
    label2.text = _dic[@"REPRESENT"];
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
 else{
      UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"工作内容:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
         CGFloat titleSize = [OAToolBox sizebyText:_dic[@"QYCONTENT"] font:12 minsWidth: 120];
  if (titleSize<44) {
    titleSize =  cell.height;
}else{
titleSize = titleSize;

}
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top,KScreenWidth-120, titleSize)];
 label2.numberOfLines = 0;
   label2.textAlignment = NSTextAlignmentRight;

 
    label2.text = _dic[@"QYCONTENT"];
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat H = 44;
if (indexPath.row == 5){
 CGFloat titleSize = [OAToolBox sizebyText:_dic[@"CONTENT"] font:12 minsWidth:120];
if (titleSize<44) {
    return 44;
}else{
return titleSize;

}
}
else{

return H;
}

}








- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 7;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
